
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

// regular expression to match only alphanumeric characters and spaces 
var regularWord = /^[\w ]+$/;

function checkForm(){
	var formCheck = true;
	
	for(i=1; i<7; i++){
		obj = document.getElementById('require_'+i);
		if(!check_empty(obj,i)){
			formCheck = false ;	
		}
	}
	return formCheck;
}
function check_empty(obj,i){
	var formCheck = true;
	if(obj.value==""){
		cross(i,'require');
		formCheck = false;
	}else if(obj.name == "email"){
			var returnval=emailfilter.test(obj.value); // using build in function call test();
			if(!returnval){
				cross(i,'Wrong email fomart');
				formCheck = false;
			}else{
				check(i)
			}
	}else if(!(obj.name == "user_pass" || obj.name == "user_confirm_pass")){
		var checkRegular= regularWord.test(obj.value);
		if(!checkRegular){
			cross(i,'Invalid characters!');
			formCheck = false;
		}else{
			check(i);
		}
	}else if(obj.name == "user_pass"){
		var getLength = obj.value.length;
		if( getLength < 8 ){
			cross(i,' Password to sort!');
			formCheck = false;
		}else{
				check(i);
			}
	}else if(obj.name == "user_confirm_pass"){ 
		var pass = document.getElementById('require_2');
		if(obj.value != pass.value){
			cross(i,' invalid password!');
			formCheck = false;
		}else{
			check(i);
		}
	}else{
		check(i);
	}
	return formCheck;
}

function check(i){
		
		document.getElementById('txt'+i).innerHTML='&nbsp;<img id="img1" alt="" src="images/icons/icon_check.gif" /> ';
}
function cross(i,msg){
	
		document.getElementById('txt'+i).innerHTML= '&nbsp;<img id="img1" alt="" src="images/icons/icon_cross.gif" /> '+ msg;
}
